package com.smartleanx.module.hrm.service.examine.examineRecordRater;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import com.smartleanx.module.hrm.controller.admin.examine.examineRecordRater.vo.*;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineRecordRater.ExamineRecordRaterDO;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.util.object.BeanUtils;

import com.smartleanx.module.hrm.dal.mysql.examine.examineRecordRater.ExamineRecordRaterMapper;


/**
 * 评分人关联 Service 实现类
 *
 * @author 
 */
@Service
@Validated
public class ExamineRecordRaterServiceImpl implements ExamineRecordRaterService {

    @Resource
    private ExamineRecordRaterMapper examineRecordRaterMapper;

    @Override
    public Integer createExamineRecordRater(ExamineRecordRaterSaveReqVO createReqVO) {
        // 插入
        ExamineRecordRaterDO examineRecordRater = BeanUtils.toBean(createReqVO, ExamineRecordRaterDO.class);
        examineRecordRaterMapper.insert(examineRecordRater);
        // 返回
        return examineRecordRater.getId();
    }

    @Override
    public void updateExamineRecordRater(ExamineRecordRaterSaveReqVO updateReqVO) {
        // 校验存在
        validateExamineRecordRaterExists(updateReqVO.getId());
        // 更新
        ExamineRecordRaterDO updateObj = BeanUtils.toBean(updateReqVO, ExamineRecordRaterDO.class);
        examineRecordRaterMapper.updateById(updateObj);
    }

    @Override
    public void deleteExamineRecordRater(Integer id) {
        // 校验存在
        validateExamineRecordRaterExists(id);
        // 删除
        examineRecordRaterMapper.deleteById(id);
    }

    private void validateExamineRecordRaterExists(Integer id) {
        if (examineRecordRaterMapper.selectById(id) == null) {
//            throw exception(EXAMINE_RECORD_RATER_NOT_EXISTS);
        }
    }

    @Override
    public ExamineRecordRaterDO getExamineRecordRater(Integer id) {
        return examineRecordRaterMapper.selectById(id);
    }

    @Override
    public PageResult<ExamineRecordRaterDO> getExamineRecordRaterPage(ExamineRecordRaterPageReqVO pageReqVO) {
        return examineRecordRaterMapper.selectPage(pageReqVO);
    }

}